﻿using System.Collections.Generic;

namespace E.Story
{
    /// <summary>
    /// 集合实用类
    /// </summary>
    public static class CollectionUtility
    {
        /// <summary>
        /// 添加字典元素
        /// </summary>
        /// <typeparam name="K">索引类型</typeparam>
        /// <typeparam name="V">值类型</typeparam>
        /// <param name="dictionary">当前字典</param>
        /// <param name="key">索引</param>
        /// <param name="value">值</param>
        public static void AddItem<K, V>(this SerializableDictionary<K, List<V>> dictionary, K key, V value)
        {
            if (dictionary.ContainsKey(key)) 
            { 
                dictionary[key].Add(value);
                return;
            }

            dictionary.Add(key, new List<V>() { value});
        }
    }
}